package com.aaa.qy127.service.impl;

import com.aaa.qy127.dao.RukuCheckDao;
import com.aaa.qy127.dao.impl.RukuCheckDaoImpl;
import com.aaa.qy127.entity.RukuCheck;
import com.aaa.qy127.service.RukuCheckService;
import com.aaa.qy127.util.Result;


import java.util.List;
import java.util.Map;

public class RukuCheckServiceImpl implements RukuCheckService{
    RukuCheckDao rukuCheckDao = new RukuCheckDaoImpl();
    /**
     * 查询等待审核的入库单
     * @param rukuCheck
     * @return
     */
    @Override
    public Result queryAllruku(RukuCheck rukuCheck) {

        List<Map<String, Object>> list = rukuCheckDao.queryAllruku(rukuCheck);
        int count = rukuCheckDao.getAllCount(rukuCheck);
        Result result = new Result(count, list);
        return result;
    }
    /**
     * 查询等待审核的入库单的详情信息
     * @param rukuCheck
     * @return
     */
    @Override
    public Result getoneruku(RukuCheck rukuCheck) {
        List<Map<String, Object>> list = rukuCheckDao.getoneruku(rukuCheck);
        int count = rukuCheckDao.getoneCount(rukuCheck);
        Result result = new Result(count, list);
        return result;
    }
    /**
     * 审核通过
     * @param rukuCheck
     * @return
     */
    @Override
    public String statusyes(RukuCheck rukuCheck) {
        int statusyes = rukuCheckDao.statusyes(rukuCheck);
        List<Map<String, Object>> getoneruku = rukuCheckDao.getrukuxiangqing(rukuCheck);
        if (statusyes>0){
            int j = 0;
            for (int i = 0; i < getoneruku.size(); i++) {
                Integer rukucount = Integer.valueOf(getoneruku.get(i).get("count").toString());
                Integer bookid=Integer.valueOf(getoneruku.get(i).get("bookid").toString());
                int bookCount = rukuCheckDao.getBookCount(bookid);
                Integer count = bookCount + rukucount;
                j = rukuCheckDao.updateBookCount(count, bookid);
            }
            if (j>0){
                return "1001";
            }else {
                return "1002";
            }
        }else {
            return "1002";
        }
    }
    /**
     * 审核不通过
     * @param rukuCheck
     * @return
     */
    @Override
    public String statusno(RukuCheck rukuCheck) {
        int statusno = rukuCheckDao.statusno(rukuCheck);
        if (statusno>0){
            int addcause = rukuCheckDao.addcause(rukuCheck);
            if (addcause>0){
                return "1001";
            }
            else {
                return "1002";
            }
        }else {
            return "1002";
        }
    }
    /**
     * 查询不通过审核的入库单信息
     * @param rukuCheck
     * @return
     */
    @Override
    public Result queryAllnotruku(RukuCheck rukuCheck) {

        List<Map<String, Object>> list = rukuCheckDao.queryAllnotruku(rukuCheck);
        int count = rukuCheckDao.getAllnotCount(rukuCheck);
        Result result = new Result(count, list);
        return result;
    }
    /**
     * 查询不通过审核的入库单的详情信息
     * @param rukuCheck
     * @return
     */
    @Override
    public Result getonenotruku(RukuCheck rukuCheck) {
        List<Map<String, Object>> list = rukuCheckDao.getoneruku(rukuCheck);
        int count = rukuCheckDao.getoneCount(rukuCheck);
        Result result = new Result(count, list);
        return result;
    }
}
